﻿using System;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Data.Common;

namespace AdoNetTest001
{
    class Program
    {
        static void Main(string[] args)
        {
            string conString = "server = .;database = Test1;uid = sa; pwd = cultural0725.";

            SqlConnection connection = new SqlConnection(conString);

            connection.Open();

            Console.WriteLine("数据库连接成功");

            //插入数据到数据库
            Console.WriteLine("请插入您需要插入的数据");
            Console.WriteLine("姓名：");
            string name = Console.ReadLine();
            Console.WriteLine("年龄:");
            int age = int.Parse(Console.ReadLine());
            //插入数据到数据库
            var ssql = "insert into Person(Name,Age)" + "Value('Bruse Lee',22)";

            //修改数据库内容
            ssql = "UPDATE Person set Age = 28 Where Name = 'Curry'";

            //删除数据库内容
            ssql = "DELETE FROM Person Where Name = 'Curry'";

            string cmdString = "select * from Class";

            SqlCommand command = new SqlCommand(cmdString, connection);

            var reader = command.ExecuteReader();

            Console.WriteLine("{0}\t{1}\t", "ID", "用户名");

            while (reader.Read())
            {
                Console.WriteLine("{0}\t{1}\t", reader["ID"], reader["ClassName"]); 
            }

            connection.Close();

            



        }
    }
}
